﻿using System;
using System.Collections.Generic;
using System.Linq;

public class Student
{
    // 属性
    public string Name { get; set; }
    public string StudentId { get; set; }
    public int Age { get; set; }
    public string Gender { get; set; }
    public string Major { get; set; }
    private Dictionary<string, double> Courses { get; set; }

    // 构造函数
    public Student(string name, string studentId, int age, string gender, string major)
    {
        Name = name;
        StudentId = studentId;
        Age = age;
        Gender = gender;
        Major = major;
        Courses = new Dictionary<string, double>();
    }

    // 添加课程及成绩
    public void AddCourse(string courseName, double score)
    {
        if (!Courses.ContainsKey(courseName))
        {
            Courses.Add(courseName, score);
        }
        else
        {
            Courses[courseName] = score; // 如果课程已存在则更新成绩
        }
    }

    // 移除课程
    public bool RemoveCourse(string courseName)
    {
        return Courses.Remove(courseName);
    }

    // 计算平均成绩
    public double GetAverageScore()
    {
        if (Courses.Count == 0)
            return 0;
        
        return Courses.Values.Average();
    }

    // 获取学生信息
    public string GetStudentInfo()
    {
        return $"姓名: {Name}, 学号: {StudentId}, 年龄: {Age}, 性别: {Gender}, 专业: {Major}";
    }

    // 重写ToString方法
    public override string ToString()
    {
        return GetStudentInfo();
    }

    // 测试
    public static void Main2()
    {
        Student student1 = new Student("张三", "2023001", 20, "男", "计算机科学");
        
        student1.AddCourse("高等数学", 90);
        student1.AddCourse("C#编程", 95);
        student1.AddCourse("数据结构", 88);
        
        Console.WriteLine(student1);
        Console.WriteLine("平均成绩: " + student1.GetAverageScore());
    }
}
